package org.linlinjava.litemall.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.linlinjava.litemall.admin.beans.annotation.LogAnno;
import org.linlinjava.litemall.admin.beans.annotation.LoginAdminId;
import org.linlinjava.litemall.admin.dto.AdminStrategyCodeDTO;
import org.linlinjava.litemall.admin.dto.AdminStrategyExtenDTO;
import org.linlinjava.litemall.admin.service.AdminLumiereCouponStrategyService;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LumiereCouponStrategy;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Api(tags = "优惠券策略API")
@RestController
@RequestMapping("/admin/couponStrategy")
@RequiredArgsConstructor
public class AdminLumiereCouponStrategyController extends ResponseUtil {

    private final AdminLumiereCouponStrategyService adminLumiereCouponStrategyService;

    @ApiOperation("优惠券策略-「列表｜奖励规则中选择优惠券策略的列表」")
    @GetMapping("ruleConfigCoupons")
    @LogAnno
    public Response ruleConfigCoupons(){
        return adminLumiereCouponStrategyService.ruleConfigCoupons();
    }


    @ApiOperation("优惠券策略-「列表」")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit",value = "数量"),
            @ApiImplicitParam(name = "page",value = "当前页"),
            @ApiImplicitParam(name = "status",value = "状态"),
            @ApiImplicitParam(name = "name",value = "优惠券策略名称"),
            @ApiImplicitParam(name = "bearing",value = "优惠券策略名称"),
            @ApiImplicitParam(name = "couponType",value = "优惠券策略类型")
    })
    @GetMapping("/strategys")
    @LogAnno
    public Response couponStrategys(@RequestParam("limit")Integer limit,
                              @RequestParam("page")Integer page,
                              @RequestParam("status")Integer status,
                              @RequestParam("name")String name,
                              @RequestParam("bearing")Short bearing,
                              @RequestParam("couponType")Integer couponType){
        return adminLumiereCouponStrategyService.couponStrategys(limit,page,status,name,bearing,couponType);
    }

    @ApiOperation("优惠券策略-「编辑」")
    @LogAnno
    @PostMapping("/edit")
    public Response editStrategys(@RequestBody LumiereCouponStrategy strategy){
        return adminLumiereCouponStrategyService.editStrategys(strategy);
    }

    @ApiOperation("优惠券策略-「创建新策略」")
    @LogAnno
    @PostMapping("/save")
    public Response saveStrategys(@RequestBody LumiereCouponStrategy strategy){
        return adminLumiereCouponStrategyService.saveStrategys(strategy);
    }


    @ApiOperation("优惠券策略-「开启｜关闭」")
    @PostMapping("/status")
    @LogAnno
    public Response statusStrategys(@RequestBody LumiereCouponStrategy strategy){
        return adminLumiereCouponStrategyService.statusStrategys(strategy);
    }

    @ApiOperation("优惠券策略-「删除｜放到回收站」")
    @ApiImplicitParam(name = "id",value = "ID")
    @LogAnno
    @GetMapping("/remove")
    public Response removeStrategys(@RequestParam("id") Long id){
        return adminLumiereCouponStrategyService.removeStrategys(id);
    }

    @ApiOperation("优惠券策略-「等级会员｜列表」")
    @LogAnno
    @GetMapping("/levelMember")
    public Response levelMemberStrategys(){
        return adminLumiereCouponStrategyService.levelMemberStrategys();
    }

    @ApiOperation("优惠券策略-「付费会员｜列表」")
    @LogAnno
    @GetMapping("/payMember")
    public Response payMemberStrategys(){
        return adminLumiereCouponStrategyService.payMemberStrategys();
    }

    @ApiOperation("优惠券策略-「实体券｜发放」")
    @LogAnno
    @PostMapping("/grant")
    public Response grantStrategyExten(@RequestBody AdminStrategyExtenDTO strategyExtenDTO, @LoginAdminId Integer adminId){
        strategyExtenDTO.setAdminId(adminId);
        return adminLumiereCouponStrategyService.grantStrategyExten(strategyExtenDTO);
    }

    @ApiOperation("优惠券策略-「策略详情」")
    @GetMapping("/details")
    @LogAnno
    public Response detailsStrategys(@RequestParam("id") Long id){
        return adminLumiereCouponStrategyService.detailsStrategys(id);
    }

    @ApiOperation("优惠券-「策略统计」")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "策略ID"),
            @ApiImplicitParam(name = "startTime",value = "开始时间"),
            @ApiImplicitParam(name = "endTime",value = "结束时间"),
            @ApiImplicitParam(name = "shopId",value = "门店ID")
    })
    @GetMapping("/statistics")
    @LogAnno
    public Response statisticsStrategys(@RequestParam("id") Long id,
                                        @RequestParam(value = "startTime",required = false) String startTime,
                                        @RequestParam(value = "endTime",required = false) String endTime,
                                        @RequestParam(value = "shopId",required = false) Integer shopId){
        return adminLumiereCouponStrategyService.statisticsStrategys(id,startTime,endTime,shopId);
    }

    @ApiOperation("优惠券策略-「领取用户列表」")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "策略ID"),
           @ApiImplicitParam(name = "userName",value = "用户名"),
           @ApiImplicitParam(name = "status",value = "使用状态"),
           @ApiImplicitParam(name = "limit",value = "limit"),
            @ApiImplicitParam(name = "page",value = "page")
    })
    @LogAnno
    @GetMapping("/users")
    public Response usersStrategys(@RequestParam("id")Long id,
                                   @RequestParam("userName")String userName,
                                   @RequestParam("status")Boolean status,
                                   @RequestParam("limit")Integer limit,
                                   @RequestParam("page")Integer page,
                                   @RequestParam(value = "startTime",required = false) String startTime,
                                   @RequestParam(value = "endTime",required = false) String endTime,
                                   @RequestParam(value = "shopId",required = false) Integer shopId){
        return adminLumiereCouponStrategyService.usersStrategys(id,userName,status,limit,page,startTime,endTime,shopId);
    }

    @ApiOperation("优惠券策略-「礼物卡｜列表」")
    @LogAnno
    @GetMapping("/gifts")
    public Response giftsList(){
        return adminLumiereCouponStrategyService.giftsList();
    }

    @ApiOperation("优惠券策略-「保存导出券码」")
    @LogAnno
    @PostMapping("/saveCode")
    public Response saveCodeStrategys(@RequestBody AdminStrategyCodeDTO strategyCodeDTO){
        return adminLumiereCouponStrategyService.saveCodeStrategys(strategyCodeDTO);
    }

    @ApiOperation("优惠券策略-「策略回收站|列表」")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit",value = "limit"),
            @ApiImplicitParam(name = "page",value = "page"),
            @ApiImplicitParam(name = "name",value = "策略名")
    })
    @LogAnno
    @GetMapping("/recycles")
    public Response recycleStrategys( @RequestParam("limit")Integer limit,
                                      @RequestParam("page")Integer page,
                                      @RequestParam("name")String name){
        return adminLumiereCouponStrategyService.recycleStrategys(limit,page,name);
    }

    @ApiOperation("优惠券策略-「我要回收｜策略」")
    @ApiImplicitParam(name = "id",value = "策略ID")
    @LogAnno
    @GetMapping("recycle")
    public Response recycletrategys(@RequestParam("id") Long id){
        return adminLumiereCouponStrategyService.recycletrategys(id);
    }

    @ApiOperation("优惠券策略-「销毁｜策略」")
    @ApiImplicitParam(name = "id",value = "策略ID")
    @LogAnno
    @GetMapping("recycleDelete")
    public Response recycleDelete(@RequestParam("id") Long id){
        return adminLumiereCouponStrategyService.recycleDelete(id);
    }


    @ApiOperation("优惠券策略-「推广券｜发放记录」")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit",value = "limit"),
            @ApiImplicitParam(name = "page",value = "page"),
            @ApiImplicitParam(name = "id",value = "策略ID")
    })
    @LogAnno
    @GetMapping("grant-logs")
    public Response grantLogs(@RequestParam("id") Long id,
                              @RequestParam("limit")Integer limit,
                              @RequestParam("page")Integer page){
        return adminLumiereCouponStrategyService.grantLogs(id,limit,page);
    }


}
